{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38b26713",
   "metadata": {},
   "outputs": [],
   "source": [
    "good_list = [\n",
    "    ('美妆蛋',20),\n",
    "    ('化妆刷',38),\n",
    "    ('花茶',50),\n",
    "    ('抱枕',60),\n",
    "]\n",
    "user_shopping_car = [\n",
    "    \n",
    "]\n",
    "\n",
    "Alipay = int(input(\"请输入你的余额：\"))\n",
    "while True:\n",
    "    print(\"-----请选择编号 欢迎选购-----\")\n",
    "    for i in range(len(good_list)):\n",
    "        print(\"商品编号:%s,商品名称:%s,商品价格:%s\"%(i,goods_list[i][0],good_list[i][1]))\n",
    "             \n",
    "             \n",
    "    choice = input(\"请正确输入购买商品的编号:\")\n",
    "    if choice.isdigit():\n",
    "        choice = int(choice)\n",
    "        if choice > len(goods_list):\n",
    "             print(\"你选择的商品不存在\")\n",
    "             \n",
    "        else:\n",
    "             if Alipay > goods_list[choice][1]:\n",
    "                user_shopping_car.append(goods_list[choice])\n",
    "                Alipay = Alipay - goods_list[choice][1]\n",
    "                print(\"【%s】已经加入你的购物车，您的【账户余额】还有:%s元\"%(goods_list[choice][0],Alipay))\n",
    "             else:\n",
    "                print(\"您的余额不足，请更换支付方式\")\n",
    "             \n",
    "    elif choice == \"q\":\n",
    "         print(\"用户购物车:\",user_shopping_car)\n",
    "         print(\"您的余额还有:\",Alipay)\n",
    "         break\n",
    "    else:\n",
    "         print(\"请输入商品编号^^\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6efee623",
   "metadata": {},
   "outputs": [],
   "source": [
    "# > 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"草莓波波奶盖\",10],\n",
    "    [\"杨枝甘露\",12],    \n",
    "]\n",
    "# 数据存放，列表的增加（append）\n",
    "shopping_list = []\n",
    "Alipay = int(input(\"请输入余额：\"))\n",
    "\n",
    "# 可以让想要重复循环的代码一直循环下去\n",
    "while True:\n",
    "    print(\"-------蜜雪冰城列表-------\")\n",
    "    for i in range(4):\n",
    "        print(i,good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "    # print(good_list[1][0],good_list[1][1])\n",
    "    # print(good_list[2][0],good_list[2][1])\n",
    "    # print(good_list[3][0],good_list[3][1])\n",
    "\n",
    "    # > 2.让用户输入商品编号进行商品的购买\n",
    "    user_choice = input(\"请输入商品编号:\")\n",
    "    # > 3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "    # 3.1用户输入商品序号（数值）\n",
    "    if user_choice.isdigit():\n",
    "        user_choice = int(user_choice)\n",
    "        if Alipay > good_list[user_choice][1]:\n",
    "            #余额足够\n",
    "            Alipay = Alipay - good_list[user_choice][1]# 更新用户余额\n",
    "            shopping_list.append(good_list[user_choice])\n",
    "            print(\"购买成功，请等待制作...您的余额还有：%s元\"%(Alipay))\n",
    "\n",
    "        else:\n",
    "            #余额不够\n",
    "            print(\"你连\"+str(good_list[user_choice][1])+\"都没有，还有脸喝蜜雪冰城！哼!\") \n",
    "        # 3.2 用户输入其他\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"感谢您的购买，欢迎下次光临\")\n",
    "        print(\"您的购物车:\",shopping_list)\n",
    "        print(\"您的余额还有：\",Alipay)\n",
    "        break\n",
    "    else:\n",
    "            print(\"您输入的商品不存在或您输入的内容有误！\")\n",
    "        # 4 用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b99bb8d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "string = \"1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dca09bf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string.isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d18b406b",
   "metadata": {},
   "outputs": [],
   "source": [
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"草莓奶盖\",10],\n",
    "    [\"杨枝甘露\",12],\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f92809eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['蜜桃四季春', 6]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "good_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8d8da12",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
